<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #xdd {
            display: inline-block;
            width: 300px;
            height: 300px;
            background-color: #c1d31d;
        }
    </style>
</head>
<body>
<div id="xdd"></div>
<script>
    let xdd = document.getElementById("xdd")//获取id为xdd的元素
// 方案1
    xdd.onclick = function () {
        console.log(this)
        let _this = this;
        setTimeout(function () {
            console.log(this)
            _this.style.backgroundColor = 'green';
        } , 200);
    }
    // 方案2
    xdd.onclick = function(){
        console.log(this)
        //开启定时器
        setTimeout(()=>{
            console.log(this)// 使用setTimeout() 方法所在环境时的this对象
            //变粉色
            this.style.backgroundColor = 'pink';
        },2000);
    }

</script>

</body>
</html>